package com.design.fitment.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;

import com.design.fitment.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

public class QuestionsAnswersFragment extends Fragment {

    @ViewInject(R.id.rg_questionsanswers)
    private RadioGroup questionsAnswersRadioGroup;
    private FragmentManager mFragmentManger;
    private android.support.v4.app.FragmentTransaction mTransaction;


    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_questions_answers, null);
        ViewUtils.inject(this, view);

        return view;
    }

    public void onResume() {
        super.onResume();
        initialize();
    }

    public void initialize() {

        mFragmentManger = getChildFragmentManager();

        questionsAnswersRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                mTransaction = mFragmentManger.beginTransaction();
                switch (i) {
                    case R.id.rbtn_answer:
                        mTransaction.replace(R.id.fl_question, new FragmentAnswerFragment());
                        mTransaction.commit();
                        break;
                    case R.id.rbtn_dynamic:
                        mTransaction.replace(R.id.fl_question, new FragmentDynamicFragment());
                        mTransaction.commit();
                        break;
                    case R.id.rbtn_newest:
                        mTransaction.replace(R.id.fl_question, new FragmentNewestFragment());
                        mTransaction.commit();
                        break;
                }

            }
        });
        View v = questionsAnswersRadioGroup.getChildAt(0);//获得radiogroup下的第一个子控件
        v.performClick();//模拟点击事件
    }


}